package com.example.auth.rest;

import cn.dev33.satoken.stp.StpUtil;
import com.example.auth.model.VO.SysMenuVO;
import com.example.auth.model.VO.UserLoginVO;
import com.example.auth.model.base.Result;
import com.example.auth.model.req.LoginReq;
import com.example.auth.model.req.RegisterReq;
import com.example.auth.service.ILoginService;
import com.example.auth.service.IRoleAndMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author xijie.wang
 * @decription:登录注册
 * @date 2022-04-11 17:37
 */

@Api(tags = "登录注册", value = "LoginController")
@RequestMapping(value = "/user")
@RestController
public class LoginController {

	@Autowired
	private ILoginService loginService;

	@Autowired
	private IRoleAndMenuService roleAndMenuService;


	@ApiOperation(value = "登录", protocols = "http", httpMethod = "POST")
	@PostMapping("/login")
	public Result<UserLoginVO> login(@Valid @RequestBody LoginReq req) {
		return loginService.login(req);
	}

	@ApiOperation(value = "注册", protocols = "http", httpMethod = "POST")
	@PostMapping("/register")
	public Result<String> register(@Valid @RequestBody RegisterReq req) {
		return loginService.register(req);
	}

	@ApiOperation(value = "退出", protocols = "http", httpMethod = "POST")
	@PostMapping("/logout")
	public Result logout() {
		StpUtil.logout();
		return Result.ok();
	}

	@ApiOperation(value = " 登录状态", protocols = "http", httpMethod = "POST")
	@PostMapping("/isLogin")
	public Result isLogin(String flag) {
		return Result.ok(StpUtil.isLogin());
	}

	@ApiOperation(value = "获取菜单列表", protocols = "http", httpMethod = "POST")
	@PostMapping("/getMenuList")
	public Result<List<SysMenuVO>> getMenuList() {
		return roleAndMenuService.getMenuList();
	}

	@ApiOperation(value = "获取权限码列表", protocols = "http", httpMethod = "POST")
	@PostMapping("/getPermissionCodeList")
	public Result<List<String>> getPermissionCodeList() {
		return roleAndMenuService.getPermissionCodeList();
	}

}

	    
